<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .code {
            width: 50px;
            height: 50px;
        }
        .code a {
            color: #c60;
            background-color: transparent;
            font-weight: bold;
            text-decoration: none;
        }
        .code-big {
            position: absolute;
            top: 10px;
            left: 80px;
        }
        .hide {
            display: none;
        }

        .show {
            width: 400px;
            display: block;
        }
    </style>
</head>
<body>
    <div class="code"><a href="#">四月的谎言</a><img src="april-1.jpg" alt="" class="code-big hide"></div>
    <script>
         window.onload = function () {
            //需求：鼠标放到a链接上，显示二维码（添加show类名，去掉hide类名）
            //      鼠标移开a链接，隐藏二维码（添加hide类名，去掉show类名）
            //1.获取事件源和相关元素
            var a = document.getElementsByTagName("a")[0];
            var div = document.getElementsByClassName("code-big")[0];
            //2.绑定事件
            a.onmouseover = fn1;   //鼠标悬停时
            a.onmouseout = fn2;     //鼠标离开时
            //定义方法
            function fn1() {
                //3.书写事件驱动程序
                div.className = "code-big show";
                //div.className = div.className.replace("hide", "show");
            }
            function fn2() {
                div.className = "code-big hide";
                //了解,字符串操作，把字符串中的hide替换成show。
                // div.className = div.className.replace("show","hide");
            }
        }
    </script>
</body>
</html>